#ifndef __USER_CONVERTOR_H__
#define __USER_CONVERTOR_H__

#include "utils/typeutils.h"
#include "roles/player/player.h"
#include <string.h>

#define COPY_CONVERTOR(new_type, old_type)\
    template <>\
    struct TypeConvertor<new_type> : public TypeConvertor<old_type>{};

//Point Convertor
template <>
struct TypeConvertor<const Point&> : public LuaConvertor
{
public:
	inline Point InitValue()
	{
		return Point(0, 0);
	}
	inline const Point& GetValue()
	{
		static Point pt;
		pt.x = LuaConvertor::GetValue<float>();
		pt.y = LuaConvertor::GetValue<float>();
		return pt;
	}
	inline int SetValue(const Point& val)
	{
		LuaConvertor::SetValue<float>(val.x);
		LuaConvertor::SetValue<float>(val.y);
		return 2;
	}
};
COPY_CONVERTOR(Point&     , const Point&)
COPY_CONVERTOR(Point      , const Point&)
COPY_CONVERTOR(const Point, const Point&)

//std::string
template <>
struct TypeConvertor<const std::string&> : public LuaConvertor
{
public:
    inline std::string InitValue()
    {
        return std::string("");
    }
    inline const std::string& GetValue()
    {
        static std::string str;
        str = LuaConvertor::GetValue<const char*>();
        return str;
    }
    inline int SetValue(const std::string val)
    {
        LuaConvertor::SetValue<const char*>(val.c_str());
        return 1;
    }
};
COPY_CONVERTOR(std::string , const std::string&)
COPY_CONVERTOR(const std::string , const std::string&)
COPY_CONVERTOR(std::string& , const std::string&)

#endif